package com.openarena.model;

import com.openarena.logic.utils.MyUtils;
import java.util.Random;
import javax.persistence.*;

@Entity
@Table(name = "players")
public class Player implements java.io.Serializable, Comparable<Player> {

    private static final Random random = new Random();
    private Integer id;
    private String name;
    private String biography;
    private String phrase;
    private String title;
    private Integer active;

    public Player() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "name")
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "biography")
    public String getBiography() {
        return this.biography;
    }

    public void setBiography(String biography) {
        this.biography = biography;
    }

    @Column(name = "phrase")
    public String getPhrase() {
        return this.phrase;
    }

    public void setPhrase(String phrase) {
        this.phrase = phrase;
    }

    @Column(name = "title")
    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Transient
    public String getScreenName() {
        String titulo = this.getTitle();
        String nombre = this.getName();
        if (MyUtils.isNull(titulo)) {
            return nombre;
        } else {
            return new String[]{titulo, nombre}[random.nextInt(2)];
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Player other = (Player) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

    @Override
    public int compareTo(Player t) {
        return id.compareTo(t.id);
    }

    @Column(name = "active")
    public Integer getActive() {
        return active;
    }

    public void setActive(Integer active) {
        this.active = active;
    }
}
